package com.jikexueyuan.downloadbythread;

import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;

public class MainActivity extends AppCompatActivity implements View.OnClickListener, ServiceConnection {

    private ProgressBar progressBar;
    private Button btnDownload;
    private boolean isDownloading;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();
        isDownloading = false;

    }

    private void initView() {

        progressBar = (ProgressBar) findViewById(R.id.progressBar);
        btnDownload = (Button) findViewById(R.id.btn_download);

        btnDownload.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (isDownloading){
            bindService(new Intent(this,DownloadService.class),this,BIND_AUTO_CREATE);
            isDownloading = true;
            btnDownload.setText("暂停");
        }else {
            btnDownload.setText("下载");
        }

    }

    @Override
    public void onServiceConnected(ComponentName name, IBinder service) {

    }

    @Override
    public void onServiceDisconnected(ComponentName name) {

    }


}
